require(['loading'], function(loading) {
	var params = getUrlParams();
	var orderId = ''; //订单号
	orderId = params.orderId?params.orderId:'';
	var payPwd;
	//数字显示隐藏
 	$(".xiaq_tb").click(function(){
 		$(".numb_box").slideUp(100);
 	});
 	$(".mm_box").click(function(){
 		$(".numb_box").slideDown(100);
 	});
 	$(".mm_box").css("display","block");
 	//密码输入
 	var i = 0;
 	var y = 0;
 	$(".nub_ggg li a").click(function(){
 		var txt = $(this).text();
 		var bb=$("#zhifumm").attr('value');
 		if($("#zhifumm").attr('value').length==6){
 			bb==txt;
 		}else{
 			bb+=txt;
 		}
 		$("#zhifumm").val(bb);
 		i++
 		if(i<6){
 			$(".mm_box li").eq(i-1).addClass("mmdd");
 		}
 		else{
 			$(".mm_box li").eq(i-1).addClass("mmdd");
 			orderDetail.item1.params.payPwd = $("#zhifumm").val();
// 			console.log(payPwd);
 			orderDetail.loadOrderSucc();
 		}
 	});
 	//删除键盘
 	$(".nub_ggg li .del").click(function(){
 		if(i>0){
 			i--
 			$(".mm_box li").eq(i).removeClass("mmdd");
 			i==0;
 			$("#zhifumm").val($("#zhifumm").val().substring(0,i))
 		}
 	});
	//复制订单号
	/*$('.sdd_copy').on('click', function() {
		copyCon = $("#orderNum").text();
		Copy(copyCon);
	});
	function Copy(str) {
		var save = function(e) {
			e.clipboardData.setData('text/plain', str);
			e.preventDefault();
		}
		document.addEventListener('copy', save);
		document.execCommand('copy');
		document.removeEventListener('copy', save);
		promptBox('复制成功');
	}*/

	var orderDetail = new Vue({
		el:'#container',
		data:{
			showLoading:false,
			hasPayPassword:false,
			isBigImg:false,
			bigImg:[],
			freightProof: [],
			orderDetailUrl: wxUrl + '/v3.2/order/orderDetails',
			orderCancelUrl: wxUrl + '/v3.2/order/cancelOrder',
			orderSuccUrl: wxUrl + '/v3.2/order/finishOrder',
			item: {
				params:{
					token: token,
					userToken: userToken,
					orderId:orderId
				}
			},
			item1: {
				params:{
					token: token,
					userToken: userToken,
					orderId:orderId,
					payPwd:payPwd
				}
			},
			data:{}
		},
		ready: function() {
	        this.loadOrderDetail();
	    },
		methods:{
			loadOrderDetail:function(){
				//获取订单详情列表
				this.$http.get(this.orderDetailUrl, this.item)
					.then(function(response) {
						var result = JSON.parse(response.body);
						this.$set('data', result.data);
						this.freightProof = result.data.order.freightProof;
						this.hasPayPassword = this.data.hasPayPassword;
//						this.freightProof.splice(0,1);
						// 复制订单号
						/*var clipboard = new Clipboard('.sdd_copy', {
					        text: function() {
					            return result.data.order.orderNo;
					        }
					    });
					    clipboard.on('success', function(e) {
					        promptBox('复制成功！');
					    });*/

					},function(response) {
						//errorCallback
					});
			},
			cancleOrder:function(){
				//取消订单
				$("#delete").show();
                $(".btn-success").one("click",function(){
                	$("#delete").hide();
                    orderDetail.$http.get(orderDetail.orderCancelUrl, orderDetail.item)
					.then(function(response) {
						var result = JSON.parse(response.body);
						if (result.code == 0) {
							promptBox("订单取消成功");
							orderDetail.loadOrderDetail();
						}
					},function(response) {
						//errorCallback
					});
                });
                $(".btn-default").one("click",function () {
                    $("#delete").hide();
                });
			},
			loadOrderSucc:function(){
//				this.item1.params.payPwd=payPwd;
				toast_showing = true;
				//获取订单详情列表
				this.$http.get(this.orderSuccUrl, this.item1)
					.then(function(response) {
						toast_showing = false;
						var result = JSON.parse(response.body);
//						console.log(result);
						if (result.code == 0) {
							location.reload();
						} else{
							toast_showing=true;
							$(".dialogCommon").css("display","block");
							$(".newtry").on("click",function(){
								i=0;
								$("#zhifumm").val("");
								$(".mm_box li").removeClass("mmdd");
								$(".dialogCommon").css("display","none");
							});
							$(".forget").on("click",function(){
								window.location.href = "../paymentPassword/passwordManagement.html";
							})
						}
					},function(response) {
						//errorCallback
				});
			},
			shank:function(){	
				if(this.hasPayPassword){
					$(".big_shank").css("display","block");
					$(".big_shank .shank").on("click",function(){
						$(".big_shank").css("display","none");
					})
				}else{
					$(".dialogCommon p").html("您还未设置支付密码");
					$(".newtry").html("取消");
					$(".forget").html("前往设置");	
					$(".dialogCommon").css("display","block");
					$(".dialog_01").css({"top":"50%","margin-top":"-0.9rem"});
					$(".newtry").on("click",function(){
						$(".dialogCommon").css("display","none");
					});
					$(".forget").on("click",function(){
						window.location.href = "../paymentPassword/paymentPassword.html";
					})
				}
			},
			seeBigImg: function(e){
				var bigImg = $(e.currentTarget).attr('src');
				this.$set('bigImg',bigImg);
				this.isBigImg = true;
			},
			closeBigImg: function(){
				this.isBigImg = false;
			}
		}
	});
});

// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory(false);
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});